import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useUserStore = defineStore(
  'user',
  () => {
    // 用户信息
    const user = ref()
    /// 设置用户信息
    const setUser = (val: any) => {
      user.value = val
    }
    // 清空用户信息

    const clearUser = () => {
      user.value = undefined
    }

    return {
      user,
      setUser,
      clearUser,
    }
  },
  {
    // 网页端配置
    // persist: true,
    /// 小程序端配置
    persist: {
      /// 调整为兼容多端API
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      },
    },
  },
)
